import { request } from "@/utils/request";
import type { ConsultOrderItem, ConsultOrderListParams, ConsultOrderPage, ConsultOrderPreData, ConsultOrderPreParams, DoctorPage, FollowType, Image, KnowledgePage, KnowledgeParams, PageParams, PartialConsult, TopDep } from "@/types/consult";

export const getKnowledgePage  = (params: KnowledgeParams) => {
  return request<KnowledgePage>("patient/home/knowledge","get",params);
}
// 获取医生列表
export const getDoctorPage = (params:PageParams)=>{
  return request<DoctorPage>('home/page/doc','get',params);
}
// 关注的类型
export const followOrUnfollow = (id:string,type:FollowType = 'doc')=>{
  return request('like','POST',{id,type});
}

// 获取所有科室信息
export const getAllDep = ()=> request<TopDep[]>('dep/all')

// 上传病情描述图片
export const uploadImg = (file:File)=> {
  const fd = new FormData()
  fd.append('file',file)
  return request<Image>('upload','post',fd)
}

// 问诊支付
export const getConsultOrderPre = (params:ConsultOrderPreParams)=> request<ConsultOrderPreData>('patient/consult/order/pre','get',params)

// 支付方式
export const createConsultOrder = (data:PartialConsult)=>request<{id:string}>('patient/consult/order','post',data)

// 获取问诊订单支付链接
export const getConsultOrderPay = (params:{
  paymentMethod:0 |1,
  orderId:string,
  payCallback:string
})=> request<{payUrl:string}>('patient/consult/pay','post',params)

export const getConsultOrederDetail =(orderId:string)=>request<ConsultOrderItem>('patient/consult/order/detail','get',{orderId})

// 获取处方订单图片
export const getPrescriptionPic = (id:string)=>request<{url:string}>(`patient/consult/prescription/${id}`)

export const evaluateConsultOrder = (data:{
  docId:string,
  orderId:string,
  score:number,
  content:string,
  anonymousFlag:0 | 1
})=> request('patient/order/evaluate','post',data)

export const getConsultOrderList = (params:ConsultOrderListParams)=>request<ConsultOrderPage>('patient/consult/order/list','get',params)

// 取消订单
export const cancelOrder = (id:string) =>request(`patient/order/cancel/${id}`,'put')

// 删除订单
export const deleteOrder = (id:string) =>request(`patient/order/${id}`,'delete')
